# !/usr/bin/env python
# -*- coding:utf-8 -*-

import pyautogui as pg      # 图形用户界面 (GUI) 操作，控制鼠标、键盘和屏幕
import pygetwindow as pw    # 获取、管理和操作窗口


JM_JSON = 'Identify/jm.json'  # jm配置文件路径
LR_JSON = 'Identify/lr.json'
TEXT_JSON = 'Identify/text.json'
screen_width, screen_height = pg.size()         # 识别左 2/3 屏幕
move_distance_x, move_distance_y = screen_width * 2 // 3, screen_height
pg.PAUSE = 0.1                 # 全局延迟（秒）


def activate_window(window_title, max_win=0):
    """激活指定标题片段的窗口，切换至前台最大化True"""
    windows = pw.getAllTitles()     # 返回所有窗口的标题列表
    matching_windows = [win for win in windows if window_title.lower() in win.lower()]  # 遍历列表,忽略大小写
    if matching_windows:
        window = pw.getWindowsWithTitle(matching_windows[0])[0]  # 获取 Window 对象
        window.activate()       # 切换到匹配窗口
        window.maximize() if max_win == 0 else None       # 最大化窗口
        return True
    else:
        return False
